﻿Imports System.Reflection

Namespace ControlLibrary
    ''' <summary>
    ''' Displays a listview of all the properties on a dbiWSFObject and raises click events for the items in the list.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class dbiWSFDetailList
        'A private variable used to access the dbiWSFObjects.
        Private myWSFObjects As dbiWSF.FrameworkObjects.objWSFObjects

#Region "Enumerations"
        ''' <summary>Determines the starting level of the list</summary>
        Enum TreeType
            Warehouse = 0
            CargoType = 1
            LoadingDockExceptions = 2
            Recurrences = 3
            All = 99
        End Enum
#End Region

#Region "Variables"
        'Variables used for the breadcrumbs and linking.
        Private CurrentLinkLevel As Long = 1
        Private CurrentTreeType As TreeType = TreeType.All
#End Region

#Region "Events"
        'Events raised by clicking on items in the list.
        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag does not contain a dbiWSF object.
        ''' </summary>
        ''' <param name="e">dbiNodeItem</param>
        Public Event OtherClicked(ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objWarehouse object.
        ''' </summary>
        ''' <param name="Warehouse">The warehouse object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event WarehouseClicked(ByRef Warehouse As dbiWSF.FrameworkObjects.objWarehouse, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objLoadingDock object.
        ''' </summary>
        ''' <param name="LoadingDock">The loadingdock object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event LoadingDockClicked(ByRef LoadingDock As dbiWSF.FrameworkObjects.objLoadingDock, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objShipment object.
        ''' </summary>
        ''' <param name="Shipment">The Shipment object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event ShipmentClicked(ByRef Shipment As dbiWSF.FrameworkObjects.objShipment, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objOrderHeader object.
        ''' </summary>
        ''' <param name="OrderHeader">The OrderHeader object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event OrderHeaderClicked(ByRef OrderHeader As dbiWSF.FrameworkObjects.objOrderHeader, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objOrderDetail object.
        ''' </summary>
        ''' <param name="OrderDetail">The OrderDetail object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event OrderDetailClicked(ByRef OrderDetail As dbiWSF.FrameworkObjects.objOrderDetail, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objCargoType object.
        ''' </summary>
        ''' <param name="CargoType">The CargoType object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event CargoTypeClicked(ByRef CargoType As dbiWSF.FrameworkObjects.objCargoType, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objLoadingDockException object.
        ''' </summary>
        ''' <param name="LoadingDockException">The LoadingDockException object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event LoadingDockExceptionClicked(ByRef LoadingDockException As dbiWSF.FrameworkObjects.objLoadingDockException, ByRef e As Dbi.WinControl.NodeClickEventArgs)

        ''' <summary>
        ''' Raises a click event when the node is clicked if a nodeitem.tag contains a dbiWSF.objRecurrence object.
        ''' </summary>
        ''' <param name="Recurrence">The Recurrence object that is in the nodeitem.tag property.</param>
        ''' <param name="e">dbiNodeItem</param>
        Public Event RecurrenceClicked(ByRef Recurrence As dbiWSF.FrameworkObjects.objRecurrence, ByRef e As Dbi.WinControl.NodeClickEventArgs)
#End Region

#Region "Constructors"

        ''' <summary>Creates a new instance of the dbiWSFDetailList.</summary>
        Public Sub New()

            ' This call is required by the Windows Form Designer.
            InitializeComponent()

            ' Add any initialization after the InitializeComponent() call.

        End Sub

        ''' <summary>Creates a new instance of the dbiWSFDetailList.</summary>
        Public Sub New(ByRef ParentWSFObject As dbiWSF.FrameworkObjects.objWSFObjects, ByRef NewTreeType As TreeType)
            Me.New()
            LoadObjects(ParentWSFObject, NewTreeType)
        End Sub

        ''' <summary>Creates a new instance of the dbiWSFDetailList.</summary>
        Public Sub New(ByRef ParentWSFObject As dbiWSF.FrameworkObjects.objWSFObjects)
            Me.new()
            LoadObjects(ParentWSFObject)
        End Sub
#End Region

#Region "ObjectLoads"
        ''' <summary>
        ''' Creates the list items for the object specified.
        ''' </summary>
        ''' <param name="ParentWSFObject">The main dbiWSFObject to map.</param>
        ''' <param name="NewTreeType">The type of tree to use. Default is All</param>
        ''' <remarks></remarks>
        Public Sub LoadObjects(ByRef ParentWSFObject As dbiWSF.FrameworkObjects.objWSFObjects, Optional ByRef NewTreeType As TreeType = TreeType.All)

            Me.DbiList1.Items.Clear()
            myWSFObjects = ParentWSFObject
            ClearLinks()
            SetLinkLevel(myWSFObjects)
            CurrentTreeType = NewTreeType
            Select Case CurrentTreeType
                Case TreeType.CargoType
                    Me.DbiList1.TitleText = "Cargo Types"
                    For Each curCargoType As dbiWSF.FrameworkObjects.objCargoType In myWSFObjects.CargoTypes.Values
                        Dim CargoNode As New Dbi.WinControl.dbiNodeItem(curCargoType.Description)
                        CargoNode.Tag = curCargoType
                        Me.DbiList1.Items.Add(CargoNode)
                    Next
                Case TreeType.LoadingDockExceptions
                    Me.DbiList1.TitleText = "LoadingDock Exceptions"
                    For Each curLoadingDockException As dbiWSF.FrameworkObjects.objLoadingDockException In myWSFObjects.LoadingDockExceptions
                        Dim DockExceptionNode As New Dbi.WinControl.dbiNodeItem(curLoadingDockException.Description)
                        DockExceptionNode.Tag = curLoadingDockException
                        Me.DbiList1.Items.Add(DockExceptionNode)
                    Next
                Case TreeType.Recurrences
                    Me.DbiList1.TitleText = "Recurrences"
                    For Each curRecurrence As dbiWSF.FrameworkObjects.objRecurrence In myWSFObjects.Recurrences
                        Dim RecurrenceNode As New Dbi.WinControl.dbiNodeItem(curRecurrence.Description)
                        RecurrenceNode.Tag = curRecurrence
                        Me.DbiList1.Items.Add(RecurrenceNode)
                    Next
                Case TreeType.Warehouse
                    Me.DbiList1.TitleText = "Warehouses"
                    For Each curWarehouse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses
                        Dim WareNode As New Dbi.WinControl.dbiNodeItem(curWarehouse.Description)
                        WareNode.Tag = curWarehouse
                        Me.DbiList1.Items.Add(WareNode)
                    Next
                Case TreeType.All

                    Me.DbiList1.TitleText = "WSF Objects"

                    Dim WarehouseNode As New Dbi.WinControl.dbiNodeItem("Warehouses")
                    For Each curWarehouse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses
                        Dim ChildNode As New Dbi.WinControl.dbiNodeItem(curWarehouse.Description)
                        ChildNode.Tag = curWarehouse
                        WarehouseNode.Items.Add(ChildNode)
                    Next
                    Me.DbiList1.Items.Add(WarehouseNode)

                    Dim CargoNode As New Dbi.WinControl.dbiNodeItem("CargoTypes")
                    For Each curCargo As dbiWSF.FrameworkObjects.objCargoType In myWSFObjects.CargoTypes.Values
                        Dim ChildNode As New Dbi.WinControl.dbiNodeItem(curCargo.Description)
                        ChildNode.Tag = curCargo
                        CargoNode.Items.Add(ChildNode)
                    Next
                    Me.DbiList1.Items.Add(CargoNode)

                    Dim DockExceptionNode As New Dbi.WinControl.dbiNodeItem("LoadingDock Exceptions")
                    For Each curDockException As dbiWSF.FrameworkObjects.objLoadingDockException In myWSFObjects.LoadingDockExceptions
                        Dim ChildNode As New Dbi.WinControl.dbiNodeItem(curDockException.Description)
                        ChildNode.Tag = curDockException
                        DockExceptionNode.Items.Add(ChildNode)
                    Next
                    Me.DbiList1.Items.Add(DockExceptionNode)

                    Dim RecurrenceNode As New Dbi.WinControl.dbiNodeItem("Recurrences")
                    For Each curRecurrences As dbiWSF.FrameworkObjects.objRecurrence In myWSFObjects.Recurrences
                        Dim ChildNode As New Dbi.WinControl.dbiNodeItem(curRecurrences.Description)
                        ChildNode.Tag = curRecurrences
                        RecurrenceNode.Items.Add(ChildNode)
                    Next
                    Me.DbiList1.Items.Add(RecurrenceNode)

            End Select

        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadWarehouseDetail(ByRef warehouse As dbiWSF.FrameworkObjects.objWarehouse)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(warehouse)
            Me.DbiList1.TitleText = warehouse.Description
            Me.getNodesFromProperties(warehouse)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadLoadingDockDetail(ByRef LoadingDock As dbiWSF.FrameworkObjects.objLoadingDock)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(LoadingDock)
            Me.DbiList1.TitleText = LoadingDock.Description
            Me.getNodesFromProperties(LoadingDock)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadShipmentDetail(ByRef Shipment As dbiWSF.FrameworkObjects.objShipment)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(Shipment)
            Me.DbiList1.TitleText = Shipment.Description
            Me.getNodesFromProperties(Shipment)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadOrderHeaderDetail(ByRef OrderHeader As dbiWSF.FrameworkObjects.objOrderHeader)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(OrderHeader)
            Me.DbiList1.TitleText = OrderHeader.OrderEntryID
            Me.getNodesFromProperties(OrderHeader)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadOrderDetailDetail(ByRef OrderDetail As dbiWSF.FrameworkObjects.objOrderDetail)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(OrderDetail)
            Me.DbiList1.TitleText = OrderDetail.LineNumber
            Me.getNodesFromProperties(OrderDetail)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadCargoTypeDetail(ByRef CargoType As dbiWSF.FrameworkObjects.objCargoType)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(CargoType)
            Me.DbiList1.TitleText = CargoType.Description
            Me.getNodesFromProperties(CargoType)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadLoadingDockExceptionDetail(ByRef LoadingDockException As dbiWSF.FrameworkObjects.objLoadingDockException)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(LoadingDockException)
            Me.DbiList1.TitleText = LoadingDockException.Description
            Me.getNodesFromProperties(LoadingDockException)
        End Sub

        ''' <summary>Loads the details for the specified object, called from LoadObjects.</summary>
        Public Sub LoadRecurrenceDetail(ByRef Recurrence As dbiWSF.FrameworkObjects.objRecurrence)
            Me.DbiList1.Items.Clear()
            ClearLinks()
            SetLinkLevel(Recurrence)
            Me.DbiList1.TitleText = Recurrence.Description
            Me.getNodesFromProperties(Recurrence)
        End Sub
#End Region

#Region "Getting Properties"

        ''' <summary>Determines if a property is a collection or not</summary>
        Private Function NonCollectionPropertyType(ByRef CurrentProperty As String) As Boolean
            Dim NonCollection As Boolean
            Select Case CurrentProperty
                Case GetType(System.Guid).ToString
                    NonCollection = True
                Case GetType(String).ToString
                    NonCollection = True
                Case GetType(System.Int64).ToString
                    NonCollection = True
                Case GetType(System.DateTime).ToString
                    NonCollection = True
                Case GetType(System.Int32).ToString
                    NonCollection = True
                Case GetType(System.Double).ToString
                    NonCollection = True
                Case GetType(dbiWSF.FrameworkObjects.ShipmentTypes).ToString
                    NonCollection = True
                Case GetType(dbiWSF.FrameworkObjects.RecurrenceTypes).ToString
                    NonCollection = True
                Case GetType(dbiWSF.FrameworkObjects.RecurrenceObjectType).ToString
                    NonCollection = True
                Case Else
                    NonCollection = False
            End Select

            Return NonCollection
        End Function

        ''' <summary>
        ''' Parses the properties on a dbiWSF Object and creates node items based on those properties.
        ''' </summary>
        ''' <param name="dbiWSFObject">The dbiWSF Object to parse.</param>
        Private Sub getNodesFromProperties(ByRef dbiWSFObject As Object)
            Dim propInfo As PropertyInfo() = dbiWSFObject.GetType.GetProperties

            Dim x As Integer

            For x = 0 To propInfo.Count - 1
                Dim newNode As New Dbi.WinControl.dbiNodeItem(propInfo(x).Name)
                newNode.Header = True
                If propInfo(x).GetValue(dbiWSFObject, Nothing) IsNot Nothing Then
                    If NonCollectionPropertyType(propInfo(x).PropertyType.FullName) Then
                        If propInfo(x).Name = "CargoTypeID" Then
                            Dim Cargo As dbiWSF.FrameworkObjects.objCargoType
                            Cargo = myWSFObjects.GetCargoFromGUID(propInfo(x).GetValue(dbiWSFObject, Nothing))
                            Dim CargoNode As New Dbi.WinControl.dbiNodeItem(Cargo.Description)
                            CargoNode.Tag = Cargo
                            newNode.Items.Add(CargoNode)
                        Else
                            newNode.Items.Add(propInfo(x).GetValue(dbiWSFObject, Nothing).ToString)
                        End If

                        Me.DbiList1.Items.Add(newNode)
                    Else
                        Dim CollectionFullName As String = propInfo(x).PropertyType.FullName
                        If propInfo(x).PropertyType.FullName.Contains("System.Collection") Then

                            Select Case propInfo(x).PropertyType.FullName
                                Case "System.Collections.Generic.List`1[[dbiWSF.FrameworkObjects+objLoadingDock, dbiWSF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                    Dim LoadingDockList As New System.Collections.Generic.List(Of dbiWSF.FrameworkObjects.objLoadingDock)
                                    LoadingDockList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curLoadingDock As dbiWSF.FrameworkObjects.objLoadingDock In LoadingDockList
                                        Dim LoadingDockNode As New Dbi.WinControl.dbiNodeItem(curLoadingDock.Description)
                                        LoadingDockNode.Tag = curLoadingDock
                                        newNode.Items.Add(LoadingDockNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)
                                Case "System.Collections.Generic.List`1[[dbiWSF.FrameworkObjects+objShipment, dbiWSF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                    Dim ShipmentList As New System.Collections.Generic.List(Of dbiWSF.FrameworkObjects.objShipment)
                                    ShipmentList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curShipment As dbiWSF.FrameworkObjects.objShipment In ShipmentList
                                        Dim ShipmentNode As New Dbi.WinControl.dbiNodeItem(curShipment.Description)
                                        ShipmentNode.Tag = curShipment
                                        newNode.Items.Add(ShipmentNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)
                                Case "System.Collections.Generic.List`1[[dbiWSF.FrameworkObjects+objLoadingDockException, dbiWSF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                    Dim LoadingDockExceptionList As New System.Collections.Generic.List(Of dbiWSF.FrameworkObjects.objLoadingDockException)
                                    LoadingDockExceptionList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curLoadingDockException As dbiWSF.FrameworkObjects.objLoadingDockException In LoadingDockExceptionList
                                        Dim LoadingDockExceptionNode As New Dbi.WinControl.dbiNodeItem(curLoadingDockException.Description)
                                        LoadingDockExceptionNode.Tag = curLoadingDockException
                                        newNode.Items.Add(LoadingDockExceptionNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)
                                Case "System.Collections.Generic.List`1[[dbiWSF.FrameworkObjects+objOrderHeader, dbiWSF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                    Dim OrderHeaderList As New System.Collections.Generic.List(Of dbiWSF.FrameworkObjects.objOrderHeader)
                                    OrderHeaderList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curOrderHeader As dbiWSF.FrameworkObjects.objOrderHeader In OrderHeaderList
                                        Dim OrderHeaderNode As New Dbi.WinControl.dbiNodeItem(curOrderHeader.OrderEntryID)
                                        OrderHeaderNode.Tag = curOrderHeader
                                        newNode.Items.Add(OrderHeaderNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)
                                Case "System.Collections.Generic.List`1[[dbiWSF.FrameworkObjects+objOrderDetail, dbiWSF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
                                    Dim OrderDetailList As New System.Collections.Generic.List(Of dbiWSF.FrameworkObjects.objOrderDetail)
                                    OrderDetailList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curOrderDetail As dbiWSF.FrameworkObjects.objOrderDetail In OrderDetailList
                                        Dim OrderDetailNode As New Dbi.WinControl.dbiNodeItem(curOrderDetail.LineNumber)
                                        OrderDetailNode.Tag = curOrderDetail
                                        newNode.Items.Add(OrderDetailNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)
                                Case "System.Collections.Generic.List`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
                                    Select Case True
                                        Case propInfo(x).DeclaringType.Name.Contains("objLoadingDockException")
                                            Dim LoadingDockList As New System.Collections.Generic.List(Of System.Guid)
                                            LoadingDockList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                            For Each curLoadingDockGuid As System.Guid In LoadingDockList
                                                Dim curLoadingDock As dbiWSF.FrameworkObjects.objLoadingDock = myWSFObjects.GetLoadingDockFromGUID(curLoadingDockGuid)
                                                Dim LoadingDockNode As New Dbi.WinControl.dbiNodeItem(curLoadingDock.Description)
                                                LoadingDockNode.Tag = curLoadingDock
                                                newNode.Items.Add(LoadingDockNode)
                                            Next
                                            Me.DbiList1.Items.Add(newNode)

                                        Case propInfo(x).DeclaringType.Name.Contains("objLoadingDock")
                                            Dim CargoTypeList As New System.Collections.Generic.List(Of System.Guid)
                                            CargoTypeList = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                            For Each curCargoGuid As System.Guid In CargoTypeList
                                                Dim curCargo As dbiWSF.FrameworkObjects.objCargoType = myWSFObjects.GetCargoFromGUID(curCargoGuid)
                                                Dim CargoNode As New Dbi.WinControl.dbiNodeItem(curCargo.Description)
                                                CargoNode.Tag = curCargo
                                                newNode.Items.Add(CargoNode)
                                            Next
                                            Me.DbiList1.Items.Add(newNode)

                                        Case propInfo(x).DeclaringType.Name.Contains("objRecurrence")
                                            Dim ObjectList As New System.Collections.Generic.List(Of System.Guid)
                                            ObjectList = propInfo(x).GetValue(dbiWSFObject, Nothing)

                                            Dim ObjectType As dbiWSF.FrameworkObjects.RecurrenceObjectType

                                            Dim y As Integer
                                            For y = 0 To propInfo.Count - 1
                                                If propInfo(y).PropertyType.FullName = GetType(dbiWSF.FrameworkObjects.RecurrenceObjectType).ToString Then
                                                    ObjectType = propInfo(y).GetValue(dbiWSFObject, Nothing)
                                                    Exit For
                                                End If
                                            Next

                                            Select Case ObjectType
                                                Case dbiWSF.FrameworkObjects.RecurrenceObjectType.DockException
                                                    For Each curLoadingDockGuid As System.Guid In ObjectList
                                                        Dim curLoadingDock As dbiWSF.FrameworkObjects.objLoadingDock = myWSFObjects.GetLoadingDockFromGUID(curLoadingDockGuid)
                                                        Dim LoadingDockNode As New Dbi.WinControl.dbiNodeItem(curLoadingDock.Description)
                                                        LoadingDockNode.Tag = curLoadingDock
                                                        newNode.Items.Add(LoadingDockNode)
                                                    Next

                                                Case dbiWSF.FrameworkObjects.RecurrenceObjectType.Shipment
                                                    For Each curShipmentGuid As System.Guid In ObjectList
                                                        Dim curShipment As dbiWSF.FrameworkObjects.objShipment = myWSFObjects.GetShipmentFromGUID(curShipmentGuid)
                                                        Dim ShipmentNode As New Dbi.WinControl.dbiNodeItem(curShipment.Description)
                                                        ShipmentNode.Tag = curShipment
                                                        newNode.Items.Add(ShipmentNode)
                                                    Next
                                            End Select
                                            Me.DbiList1.Items.Add(newNode)

                                    End Select

                                Case "System.Collections.Generic.List`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
                                    Dim Dates As New System.Collections.Generic.List(Of System.DateTime)
                                    Dates = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                    For Each curDate As System.DateTime In Dates
                                        Dim LoadingDockNode As New Dbi.WinControl.dbiNodeItem(curDate.ToString)
                                        newNode.Items.Add(LoadingDockNode)
                                    Next
                                    Me.DbiList1.Items.Add(newNode)

                                Case Else
                            End Select
                        Else
                            If propInfo(x).PropertyType.FullName.Contains("System.Byte[]") Then
                                Dim newArray As Byte() = propInfo(x).GetValue(dbiWSFObject, Nothing)
                                Dim y As Integer
                                For y = 0 To newArray.Count - 1
                                    Dim DayNode As New Dbi.WinControl.dbiNodeItem
                                    Select Case newArray(y)
                                        Case 1
                                            DayNode.Text = "Monday"
                                        Case 2
                                            DayNode.Text = "Tuesday"
                                        Case 3
                                            DayNode.Text = "Wednesday"
                                        Case 4
                                            DayNode.Text = "Thursday"
                                        Case 5
                                            DayNode.Text = "Friday"
                                        Case 6
                                            DayNode.Text = "Saturday"
                                        Case 7
                                            DayNode.Text = "Sunday"
                                    End Select
                                    newNode.Items.Add(DayNode)
                                Next
                                Me.DbiList1.Items.Add(newNode)
                            End If
                        End If
                    End If

                End If
            Next
        End Sub

#End Region

#Region "List Click Events"
        ''' <summary>Raises the click event for each object in the dbiNodeItem.Tag property.</summary>
        Private Sub DbiList1_NodeClick(ByVal sender As Object, ByVal e As Dbi.WinControl.NodeClickEventArgs) Handles DbiList1.NodeClick

            If e.Item IsNot Nothing Then
                If e.Item.Tag IsNot Nothing Then
                    Select Case e.Item.Tag.GetType.ToString
                        Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                            RaiseEvent WarehouseClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                            RaiseEvent LoadingDockClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objShipment).ToString
                            RaiseEvent ShipmentClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objOrderHeader).ToString
                            RaiseEvent OrderHeaderClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objOrderDetail).ToString
                            RaiseEvent OrderDetailClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objCargoType).ToString
                            RaiseEvent CargoTypeClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objLoadingDockException).ToString
                            RaiseEvent LoadingDockExceptionClicked(e.Item.Tag, e)
                        Case GetType(dbiWSF.FrameworkObjects.objRecurrence).ToString
                            RaiseEvent RecurrenceClicked(e.Item.Tag, e)
                        Case Else
                            'MessageBox.Show("Not a dbiWSF object in Tag")
                    End Select
                Else
                    RaiseEvent OtherClicked(e)
                End If
            End If

        End Sub
#End Region

#Region "BreadCrumbs"
        'Handles the tracking and levels of the breadcrumbs associated with the control.

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub SetLinkLevel(ByRef currentObject As Object)
            Select Case CurrentLinkLevel
                Case 1
                    Me.LinkLevel1.Tag = currentObject
                Case 2
                    Me.LinkLevel2.Tag = currentObject
                Case 3
                    Me.LinkLevel3.Tag = currentObject
                Case 4
                    Me.LinkLevel4.Tag = currentObject
                Case 5
                    Me.LinkLevel5.Tag = currentObject
                Case 6
                    Me.LinkLevel6.Tag = currentObject
                Case 7
                    Me.LinkLevel7.Tag = currentObject
            End Select
            SetLinkText()
            CurrentLinkLevel += 1
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub SetLinkText()
            For x As Integer = 1 To CurrentLinkLevel
                Dim currentLink As New Windows.Forms.LinkLabel
                Select Case x
                    Case 1
                        currentLink = Me.LinkLevel1
                    Case 2
                        currentLink = Me.LinkLevel2
                    Case 3
                        currentLink = Me.LinkLevel3
                    Case 4
                        currentLink = Me.LinkLevel4
                    Case 5
                        currentLink = Me.LinkLevel5
                    Case 6
                        currentLink = Me.LinkLevel6
                    Case 7
                        currentLink = Me.LinkLevel7
                End Select

                If currentLink.Tag IsNot Nothing Then
                    Select Case currentLink.Tag.GetType.ToString
                        Case GetType(dbiWSF.FrameworkObjects.objWSFObjects).ToString
                            currentLink.Text = "WSF Objects"
                            ToolTip1.SetToolTip(currentLink, "WSF Objects")
                        Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "Warehouse")
                        Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "LoadingDock")
                        Case GetType(dbiWSF.FrameworkObjects.objShipment).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "Shipment")
                        Case GetType(dbiWSF.FrameworkObjects.objOrderHeader).ToString
                            currentLink.Text = currentLink.Tag.OrderEntryID
                            ToolTip1.SetToolTip(currentLink, "Order Header")
                        Case GetType(dbiWSF.FrameworkObjects.objOrderDetail).ToString
                            currentLink.Text = currentLink.Tag.LineNumber
                            ToolTip1.SetToolTip(currentLink, "Order Detail")
                        Case GetType(dbiWSF.FrameworkObjects.objCargoType).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "Cargo Type")
                        Case GetType(dbiWSF.FrameworkObjects.objLoadingDockException).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "LoadingDock Exception")
                        Case GetType(dbiWSF.FrameworkObjects.objRecurrence).ToString
                            currentLink.Text = currentLink.Tag.description
                            ToolTip1.SetToolTip(currentLink, "Recurrence")
                    End Select
                End If
            Next
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel1.LinkClicked
            CurrentLinkLevel = 1
            SetLinkText()
            FollowLink(LinkLevel1.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel2.LinkClicked
            CurrentLinkLevel = 2
            SetLinkText()
            FollowLink(LinkLevel2.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel3.LinkClicked
            CurrentLinkLevel = 3
            SetLinkText()
            FollowLink(LinkLevel3.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel4_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel4.LinkClicked
            CurrentLinkLevel = 4
            SetLinkText()
            FollowLink(LinkLevel4.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel5_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel5.LinkClicked
            CurrentLinkLevel = 5
            SetLinkText()
            FollowLink(LinkLevel5.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel6_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel6.LinkClicked
            CurrentLinkLevel = 6
            SetLinkText()
            FollowLink(LinkLevel6.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub LinkLevel7_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLevel7.LinkClicked
            CurrentLinkLevel = 7
            SetLinkText()
            FollowLink(LinkLevel7.Tag)
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub FollowLink(ByRef CurrentObject As Object)
            Select Case CurrentObject.GetType.ToString
                Case GetType(dbiWSF.FrameworkObjects.objWSFObjects).ToString
                    If CurrentTreeType = TreeType.All Then
                        LoadObjects(CurrentObject)
                    Else
                        LoadObjects(CurrentObject, CurrentTreeType)
                    End If
                Case GetType(dbiWSF.FrameworkObjects.objWarehouse).ToString
                    LoadWarehouseDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objLoadingDock).ToString
                    LoadLoadingDockDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objShipment).ToString
                    LoadShipmentDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objOrderHeader).ToString
                    LoadOrderHeaderDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objOrderDetail).ToString
                    LoadOrderDetailDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objCargoType).ToString
                    LoadCargoTypeDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objLoadingDockException).ToString
                    LoadLoadingDockExceptionDetail(CurrentObject)
                Case GetType(dbiWSF.FrameworkObjects.objRecurrence).ToString
                    LoadRecurrenceDetail(CurrentObject)
            End Select
            ClearLinks()
        End Sub

        ''' <summary>Handles the tracking and levels of the breadcrumbs associated with the control.</summary>
        Private Sub ClearLinks()
            If CurrentLinkLevel < 7 Then
                Me.LinkLevel7.Text = ""
                Me.LinkLevel7.Tag = Nothing
                ToolTip1.SetToolTip(LinkLevel7, "")
                If CurrentLinkLevel < 6 Then
                    Me.LinkLevel6.Text = ""
                    Me.LinkLevel6.Tag = Nothing
                    ToolTip1.SetToolTip(LinkLevel6, "")
                    If CurrentLinkLevel < 5 Then
                        Me.LinkLevel5.Text = ""
                        Me.LinkLevel5.Tag = Nothing
                        ToolTip1.SetToolTip(LinkLevel5, "")
                        If CurrentLinkLevel < 4 Then
                            Me.LinkLevel4.Text = ""
                            Me.LinkLevel4.Tag = Nothing
                            ToolTip1.SetToolTip(LinkLevel4, "")
                            If CurrentLinkLevel < 3 Then
                                Me.LinkLevel3.Text = ""
                                Me.LinkLevel3.Tag = Nothing
                                ToolTip1.SetToolTip(LinkLevel3, "")
                                If CurrentLinkLevel < 2 Then
                                    Me.LinkLevel2.Text = ""
                                    Me.LinkLevel2.Tag = Nothing
                                    ToolTip1.SetToolTip(LinkLevel2, "")
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End Sub
#End Region

    End Class
End Namespace
